package com.oo.array_$.case_1;

import java.util.Scanner;

/**
 * DeleteElement--有一个有序整数数组，要求输入一个数字，
 * 在数组中查找是否有这个数， 如果有，将该数从数组中删除，
 * 要求删除后的数组仍然保持有序;如果没有，则显 示“数组中没有这个数!”
 *
 * @author: Jovi
 * @createTime: 2017-05-11 14:26
 **/
public class DeleteElement {
    public static void main(String[] args) {
        int[] a = {1, 4, 9, 20, 33, 50, 76, 89, 91, 100};
        int number,i,j;
        System.out.println("The original array is：");
        for (i = 0; i < a.length;i ++) {
            System.out.println(a[i] + "\t");
        }
        System.out.println("");
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a number to be removed：");
        number = sc.nextInt();
        for (i = 0; i < a.length; i++) {
            if (a[i] == number) {
                break;
            }
        }
        if (i < 10) {
            if (i <= 8) {
                for (j = i; j < 9; j++) {
                    a[j] = a[j + 1];
                }
            }
            System.out.println("\nAn array is deleted after：");
            for (i = 0; i < a.length - 1; i++) {
                System.out.println(a[i] + "\t");
            }
            System.out.println("\n");
        } else {
            System.out.println("There isn't the number in the array");
        }
    }
}
